home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / intuition / intuition_init.c < prev    next >
C/C++ Source or Header  |  1996-11-08  |  9KB  |  375 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: intuition_init.c,v 1.18 1996/11/08 11:28:02 aros Exp $
  4.  
  5.     Desc: Library header for intuition
  6.     Lang: english
  7. */
  8. #define AROS_ALMOST_COMPATIBLE
  9. #include <string.h>
  10. #include <exec/lists.h>
  11. #include <exec/resident.h>
  12. #include <exec/memory.h>
  13. #include <exec/execbase.h>
  14. #include <clib/exec_protos.h>
  15. #include <clib/intuition_protos.h>
  16. #include <clib/alib_protos.h>
  17. #include <dos/dos.h>
  18. #include <dos/dosextens.h>
  19. #include <dos/dostags.h>
  20. #include <clib/dos_protos.h>
  21. #ifndef INTUITION_CLASSES_H
  22. #   include <intuition/classes.h>
  23. #endif
  24. #ifndef UTILITY_HOOKS_H
  25. #   include <utility/hooks.h>
  26. #endif
  27. #include <utility/utility.h>
  28. #include <aros/asmcall.h>
  29. #include "intuition_intern.h"
  30.  
  31. static const char name[];
  32. static const char version[];
  33. static const APTR inittabl[4];
  34. static void *const Intuition_functable[];
  35. struct IntuitionBase *AROS_SLIB_ENTRY(init,Intuition) ();
  36. extern const char Intuition_end;
  37.  
  38. AROS_UFP3(static ULONG, rootDispatcher,
  39.     AROS_UFPA(Class *,  cl,  A0),
  40.     AROS_UFPA(Object *, obj, A2),
  41.     AROS_UFPA(Msg,      msg, A1)
  42. );
  43.  
  44. /* There has to be a better way... */
  45. struct IClass *InitImageClass (struct IntuitionBase * IntuitionBase);
  46. struct IClass *InitFrameIClass (struct IntuitionBase * IntuitionBase);
  47. struct IClass *InitICClass (struct IntuitionBase * IntuitionBase);
  48. struct IClass *InitGadgetClass (struct IntuitionBase * IntuitionBase);
  49. struct IClass *InitButtonGClass (struct IntuitionBase * IntuitionBase);
  50.  
  51. int Intuition_entry(void)
  52. {
  53.     /* If the library was executed by accident return error code. */
  54.     return -1;
  55. }
  56.  
  57. const struct Resident Intuition_resident=
  58. {
  59.     RTC_MATCHWORD,
  60.     (struct Resident *)&Intuition_resident,
  61.     (APTR)&Intuition_end,
  62.     RTF_AUTOINIT,
  63.     39,
  64.     NT_LIBRARY,
  65.     0,
  66.     (char *)name,
  67.     (char *)&version[6],
  68.     (ULONG *)inittabl
  69. };
  70.  
  71. static const char name[]="intuition.library";
  72.  
  73. static const char version[]="$VER: intuition.library 39.0 (12.8.96)\n\015";
  74.  
  75. static const APTR inittabl[4]=
  76. {
  77.     (APTR)sizeof(struct IntIntuitionBase),
  78.     (APTR)Intuition_functable,
  79.     NULL,
  80.     &AROS_SLIB_ENTRY(init,Intuition)
  81. };
  82.  
  83. static Class rootclass =
  84. {
  85.     { { NULL, NULL }, AROS_ASMFUNC_NAME(rootDispatcher), NULL, NULL },
  86.     0,        /* reserved */
  87.     NULL,    /* No superclass */
  88.     (ClassID)ROOTCLASS,  /* ClassID */
  89.  
  90.     0, 0,    /* No offset and size */
  91.  
  92.     0,        /* UserData */
  93.     0,        /* SubClassCount */
  94.     0,        /* ObjectCount */
  95.     0,        /* Flags */
  96. };
  97.  
  98. void intui_ProcessEvents (void);
  99.  
  100. struct Process * inputDevice;
  101.  
  102. AROS_LH2(struct IntuitionBase *, init,
  103.  AROS_LHA(struct IntuitionBase *, IntuitionBase, D0),
  104.  AROS_LHA(BPTR,               segList,   A0),
  105.        struct ExecBase *, sysBase, 0, Intuition)
  106. {
  107.     AROS_LIBFUNC_INIT
  108.     struct TagItem inputTask[]=
  109.     {
  110.     { NP_UserData,    0L },
  111.     { NP_Entry,    (IPTR)intui_ProcessEvents },
  112.     { NP_Input,    0L },
  113.     { NP_Output,    0L },
  114.     { NP_Name,    (IPTR)"input.device" },
  115.     { NP_Priority,    50 },
  116.     { TAG_END, 0 }
  117.     };
  118.  
  119.     SysBase = sysBase;
  120.  
  121.     NEWLIST (PublicClassList);
  122.  
  123.     if (!intui_init (IntuitionBase))
  124.     return NULL;
  125.  
  126.     /* Create semaphore and initialize it */
  127.     GetPrivIBase(IntuitionBase)->SigSem = AllocMem (sizeof(struct SignalSemaphore), MEMF_PUBLIC|MEMF_CLEAR);
  128.  
  129.     if (!GetPrivIBase(IntuitionBase)->SigSem)
  130.     return NULL;
  131.  
  132.     InitSemaphore (GetPrivIBase(IntuitionBase)->SigSem);
  133.  
  134.     /* The rootclass is created statically */
  135.     rootclass.cl_UserData = (IPTR) IntuitionBase;
  136.     AddClass (&rootclass);
  137.  
  138.     /* Add all other classes */
  139.     InitImageClass (IntuitionBase); /* After ROOTCLASS */
  140.     InitFrameIClass (IntuitionBase); /* After IMAGECLASS */
  141.  
  142.     InitICClass (IntuitionBase); /* After ROOTCLASS */
  143.  
  144.     InitGadgetClass (IntuitionBase); /* After ROOTCLASS */
  145.     InitButtonGClass (IntuitionBase); /* After GADGETCLASS */
  146.  
  147.     /* TODO Create input.device. This is a bad hack. */
  148.     inputTask[0].ti_Data = (IPTR)IntuitionBase;
  149.  
  150.     inputDevice = CreateNewProc (inputTask);
  151.  
  152.     /* You would return NULL if the init failed */
  153.     return IntuitionBase;
  154.     AROS_LIBFUNC_EXIT
  155. }
  156.  
  157. AROS_LH1(struct IntuitionBase *, open,
  158.  AROS_LHA(ULONG, version, D0),
  159.        struct IntuitionBase *, IntuitionBase, 1, Intuition)
  160. {
  161.     AROS_LIBFUNC_INIT
  162.     struct TagItem screenTags[] =
  163.     {
  164.     { SA_Depth, 4            },
  165.     { SA_Type,  WBENCHSCREEN    },
  166.     { SA_Title, (IPTR)"Workbench"   },
  167.     { TAG_END, 0 }
  168.     };
  169.  
  170.     /* Keep compiler happy */
  171.     version=0;
  172.  
  173.     if (!GfxBase)
  174.     {
  175.     if (!(GfxBase = (void *)OpenLibrary (GRAPHICSNAME, 39)) )
  176.         return NULL;
  177.     }
  178.  
  179.     if (!UtilityBase)
  180.     {
  181.     if (!(UtilityBase = (void *)OpenLibrary (UTILITYNAME, 39)) )
  182.         return NULL; /* don't close anything */
  183.     }
  184.  
  185.     if (!GetPrivIBase(IntuitionBase)->WorkBench)
  186.     {
  187.     struct Screen * screen;
  188.  
  189.     screen = OpenScreenTagList (NULL, screenTags);
  190.  
  191.     if (!screen)
  192.         return NULL;
  193.  
  194.     IntuitionBase->FirstScreen =
  195.         IntuitionBase->ActiveScreen =
  196.         GetPrivIBase(IntuitionBase)->WorkBench = screen;
  197.     }
  198.  
  199.     if (!intui_open (IntuitionBase))
  200.     return NULL;
  201.  
  202.     /* I have one more opener. */
  203.     IntuitionBase->LibNode.lib_OpenCnt++;
  204.     IntuitionBase->LibNode.lib_Flags&=~LIBF_DELEXP;
  205.  
  206.     /* You would return NULL if the open failed. */
  207.     return IntuitionBase;
  208.     AROS_LIBFUNC_EXIT
  209. }
  210.  
  211. AROS_LH0(BPTR, close,
  212.        struct IntuitionBase *, IntuitionBase, 2, Intuition)
  213. {
  214.     AROS_LIBFUNC_INIT
  215.  
  216.     /* I have one fewer opener. */
  217.     if(!--IntuitionBase->LibNode.lib_OpenCnt)
  218.     {
  219.     intui_close (IntuitionBase);
  220.  
  221.     /* Delayed expunge pending? */
  222.     if(IntuitionBase->LibNode.lib_Flags&LIBF_DELEXP)
  223.         /* Then expunge the library */
  224.         return expunge();
  225.     }
  226.     return 0;
  227.     AROS_LIBFUNC_EXIT
  228. }
  229.  
  230. AROS_LH0(BPTR, expunge,
  231.        struct IntuitionBase *, IntuitionBase, 3, Intuition)
  232. {
  233.     AROS_LIBFUNC_INIT
  234.  
  235.     /* Test for openers. */
  236.     if(IntuitionBase->LibNode.lib_OpenCnt)
  237.     {
  238.     /* Set the delayed expunge flag and return. */
  239.     IntuitionBase->LibNode.lib_Flags|=LIBF_DELEXP;
  240.     return 0;
  241.     }
  242.  
  243.     /* Free unecessary memory */
  244.     if (GetPrivIBase(IntuitionBase)->WorkBench)
  245.     CloseScreen (GetPrivIBase(IntuitionBase)->WorkBench);
  246.  
  247.     if (UtilityBase)
  248.     CloseLibrary ((struct Library *)UtilityBase);
  249.  
  250.     if (GfxBase)
  251.     CloseLibrary ((struct Library *)GfxBase);
  252.  
  253.     /* Let the driver do the same */
  254.     intui_expunge (IntuitionBase);
  255.  
  256. #ifdef DISK_BASED /* Don't remove a ROM library */
  257.     FreeImageClass ();
  258.  
  259.     /* Get rid of the library. Remove it from the list. */
  260.     Remove(&IntuitionBase->LibNode.lib_Node);
  261.  
  262.     /* Free the memory. */
  263.     FreeMem((char *)IntuitionBase-IntuitionBase->LibNode.lib_NegSize,
  264.         IntuitionBase->LibNode.lib_NegSize+IntuitionBase->LibNode.lib_PosSize);
  265. #endif
  266.  
  267.     return 0L;
  268.     AROS_LIBFUNC_EXIT
  269. }
  270.  
  271. AROS_LH0I(int, null,
  272.         struct IntuitionBase *, IntuitionBase, 4, Intuition)
  273. {
  274.     AROS_LIBFUNC_INIT
  275.     return 0;
  276.     AROS_LIBFUNC_EXIT
  277. }
  278.  
  279. #undef IntuitionBase
  280. #define IntuitionBase    ((struct IntuitionBase *)(cl->cl_UserData))
  281.  
  282. /******************************************************************************
  283.  
  284.     NAME */
  285.     AROS_UFH3(static IPTR, rootDispatcher,
  286.  
  287. /*  SYNOPSIS */
  288.     AROS_UFHA(Class  *, cl,  A0),
  289.     AROS_UFHA(Object *, o,   A2),
  290.     AROS_UFHA(Msg,      msg, A1))
  291.  
  292. /*  FUNCTION
  293.     internal !
  294.  
  295.     Processes all messages sent to the RootClass. Unknown messages are
  296.     silently ignored.
  297.  
  298.     INPUTS
  299.     cl - Pointer to the RootClass
  300.     o - This object was the destination for the message in the first
  301.         place
  302.     msg - This is the message.
  303.  
  304.     RESULT
  305.     Processes the message. The meaning of the result depends on the
  306.     type of the message.
  307.  
  308.     NOTES
  309.     This is a good place to debug BOOPSI objects since every message
  310.     should eventually show up here.
  311.  
  312.     EXAMPLE
  313.  
  314.     BUGS
  315.  
  316.     SEE ALSO
  317.  
  318.     HISTORY:
  319.     14.09.93    ada created
  320.  
  321. ******************************************************************************/
  322. {
  323.     AROS_USERFUNC_INIT
  324.     IPTR retval = 0;
  325.  
  326.     switch (msg->MethodID)
  327.     {
  328.     case OM_NEW: {
  329.     cl = _OBJECT(o)->o_Class;
  330.  
  331.     /* Nur Speicher besorgen. Im Object steht, wieviel.
  332.        (Das Object ist keines. Es ist der Class-Pointer selbst !) */
  333.     retval = (IPTR) AllocMem (cl->cl_InstOffset
  334.         + cl->cl_InstSize
  335.         + sizeof (struct _Object)
  336.         , MEMF_ANY
  337.         );
  338.  
  339.     retval = (IPTR) BASEOBJECT(retval);
  340.     break; }
  341.  
  342.     case OM_DISPOSE:
  343.     /* Speicher freigeben. Aufrufer ist verantwortlich,
  344.        dass bereits alles andere freigegeben wurde ! */
  345.     FreeMem (_OBJECT(o)
  346.         , cl->cl_InstOffset
  347.         + cl->cl_InstSize
  348.         + sizeof (struct _Object)
  349.         );
  350.     break;
  351.  
  352.     case OM_ADDTAIL:
  353.     /* Fuege <o> an Liste an. */
  354.     AddTail (((struct opAddTail *)msg)->opat_List,
  355.             (struct Node *) _OBJECT(o));
  356.     break;
  357.  
  358.     case OM_REMOVE:
  359.     /* Entferne Object aus der Liste */
  360.     Remove ((struct Node *) _OBJECT(o));
  361.     break;
  362.  
  363.     default:
  364.     /* Ignore */
  365.     break;
  366.  
  367.     } /* switch */
  368.  
  369.     return (retval);
  370.     AROS_USERFUNC_EXIT
  371. } /* rootDispatcher */
  372.  
  373.  
  374.  
  375.